package game

import servers.DbServer;
import servers.RpcServer;
import core.Colony
import core.Settings

class Game {
	
	boolean over = false
	final Colony col;
	
	public Game(Colony theColony) {
		col = theColony
	}
	
	public void start() {
		/* TODO
		 * - load previous state
		 * - start XML/RPC server
		 * - start HTTP server
		 */
		DbServer.start()
		RpcServer.start()
		// TODO create initial state (registered members, initial buidings)
	}
	
	public void loop() {
		int day = 1
		while (!over) {
			// beginning of day
			col.produce()
			col.processEvents(col.randomEvents())
			// main day
			//processPlayerActions()
			// end of day 
			//col.consume()
			//col.storeSurpluses()
			//col.updateStats()		
			saveState(day)
			day++
			over = true	
		}
	}

	void saveState(int day){
		File f = new File('data/colony_state/day'+day+'.xml')
		f.write(col.toXML())
	}
}
